package com.hnkywl.sts.service.report;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.report.XslrDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-15
 * Time: 下午9:23
 * To change this template use File | Settings | File Templates.
 */
@Service
public class XslrService {
    private XslrDao xslrDao;

    /**
     * 销售利润报表
     *
     * @param gsid
     * @param khid
     * @return
     */
    public String xslrList(Long gsid, Date startDate, Date endDate, Long khid, Integer xslx, Integer jszt) {
        Map<String, List<Map>> result = xslrDao.xslrList(gsid, startDate, endDate, khid, xslx, jszt);
        List<Map> rows = (List<Map>) result.get("rows");
        List<Map> footer = (List<Map>) result.get("footer");
        Gson gson = new GsonBuilder().create();
        String footerJson = gson.toJson(footer);
        String rowsJson = gson.toJson(rows);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson + "}";
        return json;
    }

    /**
     * 销售利润汇总
     *
     * @param gsid
     * @param startDate
     * @param endDate
     * @param khid
     * @param xslx
     * @param jszt
     * @return
     */
    public String xslrhzList(Long gsid, Date startDate, Date endDate,Integer xslx, Integer jszt) {
        Map<String, List<Map>> result = xslrDao.xslrhzList(gsid, startDate, endDate, xslx, jszt);
        List<Map> rows = (List<Map>) result.get("rows");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String json = "{\"rows\":" + rowsJson + "}";
        return json;
    }


    /**
     * 大屏展示：销售利润报表
     */
    public Map<String, Object> xslrListForScreen(int pageNo, int pageSize) {
//        Calendar c = Calendar.getInstance();
//        c.add(Calendar.MONTH,-2);
        Map<String, Object> result = xslrDao.xslrListForScreen(new Date(), new Date(), pageNo, pageSize);
        return result;
    }

    /**
     * 大屏展示：经营收入饼状图
     */
    public Map<String, Object> findXslrPieForScreen() {
        return xslrDao.findXslrPieForScreen(new Date(), new Date());
    }

    @Autowired
    public void setXslrDao(XslrDao xslrDao) {
        this.xslrDao = xslrDao;
    }
}
